<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Time extends CI_Controller {
 function __construct()
 {
   parent::__construct();
   $this->load->model('muser');
   $this->load->library('form_validation');
   $this->load->library('pagination');
   $this->load->library('my_datatables');
   $this->load->library('my_time');
 }
 function index(){ 	
 	 	$this->load->view('_header');
   		$this->load->view('time/time_view'); 
   		$this->load->view('_footer');	 
 }
function viewAll(){
	 if( !empty( $_POST ) ) {
	 	$data=array(			
			"FromDate"=>$this->input->post('FromDate'),
			"ToDate"=>$this->input->post('ToDate')
		);	
		 $this->my_time->makeMonthTimeAllStaff($data['FromDate'],$data['ToDate']);
		 $this->session->set_userdata($data);
	 }		 
		 /*$config['base_url'] = base_url().'time/viewAll'; 
		 $config['total_rows'] = $this->muser->num_rows('Time');
		 
		 $config['per_page'] = 10; // xác định số record ở mỗi trang  
	     $config['uri_segment'] = 3; // xác định segment chứa page number  
		 $this->pagination->initialize($config); 
		 $data['result']=$this->muser->getAMonthTime($data['FromDate'],$data['ToDate'],$config['per_page'],$this->uri->segment(3));*/
		 $this->load->view('_header');
     	 $this->load->view('time/viewAll'); 
     	$this->load->view('_footer');
	
}
 function view($str){
	$result=$this->muser->getRdata('MonthTime','MonthTime_ID',$str);
	$data['result']=$result;
	$this->load->view('_header');
	$this->load->view('time/viewTime_view',$data);	
	$this->load->view('_footer');
}
 function delete($MonthTime_ID){
	$this->muser->delColumn('MonthTime','MonthTime_ID',$MonthTime_ID);
	redirect('time/index');
 }
 
 function AllMonthTime(){
 	$this->load->view('_header');
	$this->load->view('time/time');
	$this->load->view('_footer');	
 }
 
 
 function edit1 ()
 {
 	$DT=array(
						"MonthTime_ID"=>$this->input->post('MonthTime_ID'),
						"Staff_ID"=>$this->input->post('Staff_ID'),						
						"FromDate"=>$this->input->post('FromDate'),
						"ToDate"=>$this->input->post('ToDate'),
						"WorkingDay"=>$this->input->post('WorkingDay'),
						"ULDay"=>$this->input->post('ULDay'),
						"SLDay"=>$this->input->post('SlDay'),
						"PLDay"=>$this->input->post('PLDay'),
						"ALDay"=>$this->input->post('ALDay'),
						"OT_Weekday"=>$this->input->post('OT_Weekday'),
						"ON_Weekday"=>$this->input->post('ON_Weekday'),
						"Time_Saturday"=>$this->input->post('Time_Saturday'),
						"OT_Saturday"=>$this->input->post('OT_Saturday'),
						"ON_Saturday"=>$this->input->post('ON_Saturday'),
						"ON_Sunday"=>$this->input->post('ON_Sunday'),
						"OT_Holiday"=>$this->input->post('OT_Holiday'),						
						"ON_Holiday"=>$this->input->post('ON_Holiday'),
						"PerformanceBonus"=>$this->input->post('PerformanceBonus'),
						"P_Desciption"=>$this->input->post('P_Desciption'),
						"ComDeduction"=>$this->input->post('ComDeduction'),
						"C_Desciption"=>$this->input->post('C_Desciption'),
						"N"=>$this->input->post('N'),
						"F"=>$this->input->post('F')						
				);
	$this->muser->updateData('MonthTime','MonthTime_ID',$DT['MonthTime_ID'],$DT);
	$data['error']='Edit successful!';	 	
	redirect('time/AllMonthTime',$data);		
 } 
 function edit($str)
 {	
 	$result=$this->muser->getRdata('MonthTime','MonthTime_ID',$str);
	$data['result']=$result;
	$this->load->view('_header');
	$this->load->view('time/editTime_view',$data);	
	$this->load->view('_footer');
 }
 
 function check_Contract($str){
 		return $this->muser->checkData('Contract','Contract_ID',$str);		
 }
 function getStaffID(){
 	 $lab1=$this->muser->getData('Staff');
	 foreach ($lab1 as $row) {
		 $lab[$row->Staff_ID]=$row->Staff_ID.'-'.$row->FullName;
	 }
	 return $lab;
 }
  function getDepartment(){
 	 $lab1=$this->muser->getData('Department');
	 foreach ($lab1 as $row) {
		 $lab[$row->Department_ID]=$row->Department_ID.'-'.$row->Department;
	 }
	 return $lab;
 }
   function getSection(){
 	 $lab1=$this->muser->getData('Session');
	 foreach ($lab1 as $row) {
		 $lab[$row->Session_ID]=$row->Session_ID.'-'.$row->SessionName;
	 }
	 return $lab;
 }
 function getContractType(){
 	 $lab1=$this->muser->getData('ContractType');
	 foreach ($lab1 as $row) {
		 $lab[$row->ContractType_ID]=$row->ContractType_ID.'-'.$row->ContractTypeName;
	 }
	 return $lab;
 }
 function table(){
 	$this->my_datatables
 		->select('MonthTime_ID,MonthTime.Staff_ID,FullName,FromDate,ToDate,WorkingDay,WorkedDay,SLDay')
		->from('MonthTime')
		->add_column('Edit','<a href="'.base_url().'time/edit/$1">Edit</a>','MonthTime_ID')
		->join('Staff','Staff.Staff_ID=MonthTime.Staff_ID');
	echo $this->my_datatables->generate();
 }
 function table2(){
 	$FromDate=$this->session->userdata('FromDate');
	$ToDate=$this->session->userdata('ToDate');	
 	$this->my_datatables
 		->select('MonthTime_ID,MonthTime.Staff_ID,Staff.FullName,FromDate,ToDate,WorkingDay,WorkedDay,SLDay')
		->where('FromDate',$FromDate)
		->where('ToDate',$ToDate)
		->join('Staff','MonthTime.Staff_ID=Staff.Staff_ID')
		->from('MonthTime')		
		->add_column('Edit','<a href="'.base_url().'time/edit/$1">Edit</a>','MonthTime_ID');		
	echo $this->my_datatables->generate();	
 }
}